import api from "../../utils/api"
var app = getApp();
Page({
  data: {
    user:{
      longitude: 23.099954,
      latitude: 113.326720,
    },
    markers: [
    //   {
    //   iconPath: "../../img/map_icon2.png",
    //   id: 0,
    //   latitude: 23.099954,
    //   longitude: 113.326720,
    //   width: 20,
    //   height: 30
    // },
    //   {
    //     iconPath: "../../img/map_icon3.png",
    //     id: 0,
    //     latitude: 23.099984,
    //     longitude: 113.324542,
    //     width: 20,
    //     height: 30
    //   },
    //   {
    //     iconPath: "../../img/map_icon3.png",
    //     id: 0,
    //     latitude: 23.098984,
    //     longitude: 113.323542,
    //     width: 20,
    //     height: 30
    //   },
    //   {
    //     iconPath: "../../img/map_icon3.png",
    //     id: 0,
    //     latitude: 23.095984,
    //     longitude: 113.320542,
    //     width: 20,
    //     height: 30
    //   },
    //   {
    //     iconPath: "../../img/map_icon3.png",
    //     id: 0,
    //     latitude: 23.100984,
    //     longitude: 113.334542,
    //     width: 20,
    //     height: 30
    //   }
      ],
    polyline: [{
      points: [],
      color: "#FF0000DD",
      width: 2,
      dottedLine: true
    }],
    // controls: [{
    //   id: 1,
    //   iconPath: '/resources/location.png',
    //   position: {
    //     left: 0,
    //     top: 300 - 50,
    //     width: 50,
    //     height: 50
    //   },
    //   clickable: true
    // }]
  },
  regionchange(e) {
    console.log(e.type)
  },
  markertap(e) {
    console.log("点击气泡");
    console.log(e.markerId);
    /**
     * 跳转到个人详情主页
     */
    wx.navigateTo({
      url: '../zhanghu/redmothordetail/redmothordetail?y_id=' + e.markerId,
    })
  },
  controltap(e) {
    console.log(e.controlId)
  },
  onLoad:function(){
    this.getAllLocation();
    this.getMyLocation();
  },
  getAllLocation(){
    var that = this;
    wx.request({
      url: api.getAllLoation,
      data:{},
      headers:{
        "content-type": "application/x-www-form-urlencoded"
      },
      method:"POST",
      success:function(response){
        console.log("获取所有用户地理位置成功！");
        console.log(response.data.data);
        var tempArr = [];
        // debugger;
        for(var i = 0; i < response.data.data.length;i++){
          if (response.data.data[i].id == app.globalData.openid){
            // debugger;
            // that.data.user.longitude = response.data.data[i].longitude;
            // that.data.user.latitude = response.data.data[i].latitude;
            // that.setData({
            //   user:that.data.user
            // });
            tempArr.push({
              iconPath: "../../img/map_icon2.png",
              id: response.data.data[i].id,
              latitude: response.data.data[i].latitude,
              longitude: response.data.data[i].longitude,
              // title: "123",
              width: 20,
              height: 30
            })
            
              continue;
          }
            if (response.data.data[i].latitude != null && response.data.data[i].longitude != null){
              tempArr.push({
                iconPath: "../../img/map_icon2.png",
                id: response.data.data[i].id,
                latitude: response.data.data[i].latitude,
                longitude: response.data.data[i].longitude,
                title:"",
                width: 20,
                height: 30
              })
            }
            
           
         
          tempArr.push({
            iconPath: "../../img/map_icon3.png",
            id: i,
            // title:"123",
            latitude: response.data.data[i].latitude,
            longitude: response.data.data[i].longitude,
            width: 20,
            height: 30
          });

          

        }
        // that.setData({
        //     markers: tempArr
        //   });
      }
    })
  },
  /**
   * 获取当前的地理位置
   */
  getMyLocation:function(){
    debugger;
    wx.getLocation({
      success: function(res) {
        console.log("获取当前地理位置");
        console.log(res);
      },
    })
  }
})